package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DecisionTable;
import com.ruoyi.system.service.IDecisionTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 决策管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/system/table")
public class DecisionTableController extends BaseController
{
    @Autowired
    private IDecisionTableService decisionTableService;

    /**
     * 查询决策管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(DecisionTable decisionTable)
    {
        startPage();
        List<DecisionTable> list = decisionTableService.selectDecisionTableList(decisionTable);
        return getDataTable(list);
    }

    /**
     * 导出决策管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:table:export')")
    @Log(title = "决策管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DecisionTable decisionTable)
    {
        List<DecisionTable> list = decisionTableService.selectDecisionTableList(decisionTable);
        ExcelUtil<DecisionTable> util = new ExcelUtil<DecisionTable>(DecisionTable.class);
        util.exportExcel(response, list, "决策管理数据");
    }

    /**
     * 获取决策管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:table:query')")
    @GetMapping(value = "/{decisionId}")
    public AjaxResult getInfo(@PathVariable("decisionId") Long decisionId)
    {
        return success(decisionTableService.selectDecisionTableByDecisionId(decisionId));
    }

    /**
     * 根据 alert_id 查询决策管理信息
     */
    @PreAuthorize("@ss.hasPermi('system:table:query')")
    @GetMapping(value = "/alert/{alertId}")
    public AjaxResult getInfoByAlertId(@PathVariable("alertId") Long alertId)
    {
        return success(decisionTableService.selectDecisionTableByAlertId(alertId));
    }

    /**
     * 新增决策管理
     */
    @PreAuthorize("@ss.hasPermi('system:table:add')")
    @Log(title = "决策管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DecisionTable decisionTable)
    {
        return toAjax(decisionTableService.insertDecisionTable(decisionTable));
    }

    /**
     * 修改决策管理
     */
    @PreAuthorize("@ss.hasPermi('system:table:edit')")
    @Log(title = "决策管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DecisionTable decisionTable)
    {
        return toAjax(decisionTableService.updateDecisionTable(decisionTable));
    }

    /**
     * 删除决策管理
     */
    @PreAuthorize("@ss.hasPermi('system:table:remove')")
    @Log(title = "决策管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{decisionIds}")
    public AjaxResult remove(@PathVariable Long[] decisionIds)
    {
        return toAjax(decisionTableService.deleteDecisionTableByDecisionIds(decisionIds));
    }
}
